package com.xhs.service.impl;

import cn.dev33.satoken.sign.SaSignUtil;
import com.xhs.message.Result;
import com.xhs.message.ReturnResult;
import com.xhs.service.SignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @desc:
 * @projectName: java-tools-parent
 * @author: xhs
 * @date: 2023-8-27 027 16:36
 * @version: JDK 1.8
 */
@Slf4j
@Service
public class SignServiceImpl implements SignService {

    /**
     * 生成签名 POST请求方式
     *
     * @param paramsMap 参数
     * @return ReturnResult<Object>
     */
    @Override
    public ReturnResult<Object> signGet(Map<String, Object> paramsMap) {
        log.info("生成签名的入参-paramsMap:{}", paramsMap);
        String signParams = SaSignUtil.addSignParamsAndJoin(paramsMap);
        log.info("生成签名后的参数-signParams:{}", signParams);
        return ReturnResult.build(Result.SUCCESS).setData(signParams);
    }

    /**
     * 生成签名 POST请求方式
     *
     * @param paramsMap 参数
     * @return ReturnResult<Object>
     */
    @Override
    public ReturnResult<Object> signPost(Map<String, Object> paramsMap) {
        log.info("生成签名的入参-paramsMap:{}", paramsMap);
        Map<String, Object> map = SaSignUtil.addSignParams(paramsMap);
        log.info("生成签名后的参数-signParams:{}", map);
        return ReturnResult.build(Result.SUCCESS).setData(map);
    }
}
